package interview.huawei.myself.online1.v1;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * @Author CandyWall
 * @Date 2022/3/10--15:30
 * @Description
 */
public class Consumer implements Runnable {
    private LinkedBlockingQueue<Integer> queue;
    private int type;

    public Consumer(LinkedBlockingQueue<Integer> queue, int type) {
        this.queue = queue;
        this.type = type;
    }

    @Override
    public void run() {
        while (true) {
            Integer num = queue.poll();
            if (num != null) {

                if (num % 2 == 0) {
                    if (type == 0) {
                        System.out.println(Thread.currentThread().getName() + ": 消费了" + num);
                    }
                } else {
                    if (type == 1) {
                        System.out.println(Thread.currentThread().getName() + ": 消费了" + num);
                    }
                }
            }
        }
    }
}
